/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */

package com.simon.mengkou.system.global;


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;

import com.ouertech.android.agm.lib.base.utils.UtilList;
import com.ouertech.android.agm.lib.base.utils.UtilLog;
import com.ouertech.android.agm.lib.base.utils.UtilString;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Address;
import com.simon.mengkou.data.bean.base.Follow;
import com.simon.mengkou.data.bean.base.ImageTag;
import com.simon.mengkou.data.bean.base.Message;
import com.simon.mengkou.data.bean.base.NewOrder;
import com.simon.mengkou.data.bean.base.Order;
import com.simon.mengkou.data.bean.base.Shop;
import com.simon.mengkou.data.bean.base.Store;
import com.simon.mengkou.data.bean.base.Topic;
import com.simon.mengkou.data.bean.req.FollowReq;
import com.simon.mengkou.data.bean.req.ShareOrderLikeReq;
import com.simon.mengkou.data.enums.EMessageType;
import com.simon.mengkou.system.constant.CstOuer.BROADCAST_ACTION;
import com.simon.mengkou.system.constant.CstOuer.KEY;
import com.simon.mengkou.data.bean.base.Niudan;
import com.simon.mengkou.system.constant.CstOuer;
import com.simon.mengkou.system.service.OuerService;
import com.simon.mengkou.ui.activity.AboutActivity;
import com.simon.mengkou.ui.activity.CartNewActivity;
import com.simon.mengkou.ui.activity.EditAddressActivity;
import com.simon.mengkou.ui.activity.AddressManagerActivity;
import com.simon.mengkou.ui.activity.BrandActivity;
import com.simon.mengkou.ui.activity.CartActivity;
import com.simon.mengkou.ui.activity.CouponActivity;
import com.simon.mengkou.ui.activity.CreateActivity;
import com.simon.mengkou.ui.activity.ExpressActivity;
import com.simon.mengkou.ui.activity.FanActivity;
import com.simon.mengkou.ui.activity.FeedbackActivity;
import com.simon.mengkou.ui.activity.FollowActivity;
import com.simon.mengkou.ui.activity.GoodsTopicActivity;
import com.simon.mengkou.ui.activity.GroupActivity;
import com.simon.mengkou.ui.activity.HotSaleActivity;
import com.simon.mengkou.ui.activity.ImageTagEditActivity;
import com.simon.mengkou.ui.activity.ImageTagSearchActivity;
import com.simon.mengkou.ui.activity.LoginActivity;
import com.simon.mengkou.ui.activity.MainTabActivity;
import com.simon.mengkou.ui.activity.MessageActivity;
import com.simon.mengkou.ui.activity.NDNiudanActivity;
import com.simon.mengkou.ui.activity.NDOrderActivity;
import com.simon.mengkou.ui.activity.NDRulesActivity;
import com.simon.mengkou.ui.activity.OrderActivity;
import com.simon.mengkou.ui.activity.OrderConfirmActivity;
import com.simon.mengkou.ui.activity.OrderCouponActivity;
import com.simon.mengkou.ui.activity.OrderDetailActivity;
import com.simon.mengkou.ui.activity.OrderNewConfirmActivity;
import com.simon.mengkou.ui.activity.OrderNewDetailActivity;
import com.simon.mengkou.ui.activity.PayResultActivity;
import com.simon.mengkou.ui.activity.ProductCompartmentActivity;
import com.simon.mengkou.ui.activity.ProductDetailActivity;
import com.simon.mengkou.ui.activity.ProductListActivity;
import com.simon.mengkou.ui.activity.ScoreActivity;
import com.simon.mengkou.ui.activity.SearchTagActivity;
import com.simon.mengkou.ui.activity.SettingActivity;
import com.simon.mengkou.ui.activity.ShareOrderDetailActivity;
import com.simon.mengkou.ui.activity.TagPostsActivity;
import com.simon.mengkou.ui.activity.TopicDetailActivity;
import com.simon.mengkou.ui.activity.UserActivity;
import com.simon.mengkou.ui.activity.UserCollectionActivity;
import com.simon.mengkou.ui.activity.UserModifyActivity;
import com.simon.mengkou.ui.activity.UserModifyPwdActivity;
import com.simon.mengkou.ui.activity.UserPhoneActivity;
import com.simon.mengkou.ui.activity.UserPwdActivity;
import com.simon.mengkou.ui.activity.UserTopicActivity;
import com.simon.mengkou.ui.activity.VideoListActivity;
import com.simon.mengkou.ui.activity.VideoPlayerActivity;
import com.simon.mengkou.ui.activity.WebActivity;
import com.simon.mengkou.ui.activity.WebTopicDetailActivity;
import com.simon.mengkou.ui.activity.WishListActivity;
import com.simon.mengkou.ui.fragment.NDCenterFragment;
import com.simon.mengkou.ui.fragment.NDCouponFragment;
import com.simon.mengkou.ui.fragment.NDDetailFragment;
import com.simon.mengkou.ui.fragment.NDImageFragment;
import com.simon.mengkou.ui.fragment.NDOptionsFragment;
import com.simon.mengkou.ui.fragment.NDPlayFragment;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.xiaomi.mipush.sdk.MiPushMessage;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author : Zhenshui.Xia
 * @date   :  2014年11月18日
 * @desc   : 管理activity跳转、service启动、broadcast发送、fragment切换
 * 		message分发、H5跳转本地
 */
public class OuerDispatcher {
    //==========activity跳转=================

    /**
     * 打开登录界面
     * @param context
     */
    public static void presentLoginActivity(Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent(context, LoginActivity.class);
        context.startActivity(intent);
    }

    /**
     * (注册or忘记密码）获取手机号码界面
     *
     * @param context
     */
    public static void presentUserPhoneActivity(@NonNull Context context, int type) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, UserPhoneActivity.class);
        intent.putExtra(KEY.TYPE, type);
        context.startActivity(intent);
    }

    /**
     * (注册or忘记密码）设置密码界面
     *
     * @param context
     */
    public static void presentUserPwdActivity(@NonNull Context context, int type,
                                         String phone, String code) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, UserPwdActivity.class);
        intent.putExtra(KEY.TYPE, type);
        intent.putExtra(KEY.PHONE, phone);
        intent.putExtra(KEY.CODE, code);
        context.startActivity(intent);
    }

    /**
     * 打开粉丝界面
     * @param context
     * @param userId
     */
    public static void presentFanActivity(Context context, String userId) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent(context, FanActivity.class);
        intent.putExtra(CstOuer.KEY.USER_ID, userId);
        context.startActivity(intent);
    }

    /**
     * 打开关注界面
     * @param context
     * @param userId
     */
    public static void presentFollowActivity(Context context, String userId) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent(context, FollowActivity.class);
        intent.putExtra(CstOuer.KEY.USER_ID, userId);
        context.startActivity(intent);
    }

    /**
     * 打开积分说明界面
     * @param context
     */
    public static void presentScoreActivity(Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent(context, ScoreActivity.class);
        context.startActivity(intent);
    }

    /**
     * 打开界面
     * @param context
     */
    public static void presentMainTabActivity(Context context) {
        presentMainTabActivity(context, 0);
    }


    /**
     * 打开界面
     * @param context
     * @param index
     */
    public static void presentMainTabActivity(Context context, int index) {
        if(context == null || index < 0) {
            return;
        }

        Intent intent = new Intent(context, MainTabActivity.class);
        intent.putExtra(CstOuer.KEY.INDEX, index);
        context.startActivity(intent);
    }

    /**
     * 打开发布帖子界面
     * @param context
     */
    public static void presentCreateActivity(Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent(context, CreateActivity.class);
        context.startActivity(intent);
    }

    /**
     * 打开消息界面
     * @param context
     */
    public static void presentMessageActivity(Context context) {
        presentMessageActivity(context, 0);
    }

    /**
     * 打开消息界面
     * @param context
     */
    public static void presentMessageActivity(Context context, int index) {
        if(context == null || index < 0) {
            return;
        }

        Intent intent = new Intent(context, MessageActivity.class);
        intent.putExtra(CstOuer.KEY.INDEX, index);
        context.startActivity(intent);
    }

    /**
     * 打开设置界面
     * @param context
     */
    public static void presentSettingActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, SettingActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到关于我们页面
     *
     * @param context
     */
    public static void presentAboutActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, AboutActivity.class);
        context.startActivity(intent);

    }

    /**
     * 跳转到意见反馈页面
     *
     * @param context
     */
    public static void presentFeedbackActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, FeedbackActivity.class);
        context.startActivity(intent);

    }


    /**
     * 打开扭蛋计划活动规则界面
     * @param context
     */
    public static void presentRulesActivity(Context context) {
        if(context != null) {
            Intent intent = new Intent(context, NDRulesActivity.class);
            context.startActivity(intent);
        }
    }

    /**
     * 扭蛋界面
     * @param context
     */
    public static void presentNiudanActivity(Context context, int fragment) {
        if(context != null) {
            Intent intent = new Intent(context, NDNiudanActivity.class);
            intent.putExtra(CstOuer.KEY.FRAGMENT, fragment);
            context.startActivity(intent);
        }
    }

    /**
     * 扭蛋订单界面
     * @param context
     * @param niudans
     */
    public static void presentOrderActivity(Context context, ArrayList<Niudan> niudans) {
        if(context != null  && UtilList.isNotEmpty(niudans)) {
            Intent intent = new Intent(context, NDOrderActivity.class);
            intent.putExtra(CstOuer.KEY.NIUDAN, niudans);
            context.startActivity(intent);
        }
    }


    /**
     * 跳转到web界面
     *
     * @param context
     */
    public static void presentWebActivity(Context context, String url, String title) {
        if (context == null || UtilString.isBlank(url)) {
            return;
        }

        Intent intent = new Intent(context, WebActivity.class);
        intent.putExtra(KEY.URL, url);
        intent.putExtra(KEY.TITLE , title);
        context.startActivity(intent);
    }

    /**
     * 跳转到商品详情界面
     *
     * @param context
     */
    public static void presentProductDetailActivity(Context context, String id) {
        if (context == null || UtilString.isBlank(id)) {
            return;
        }

        Intent intent = new Intent(context, ProductDetailActivity.class);
        intent.putExtra(KEY.ID, id);
        context.startActivity(intent);
    }

    /**
     * 跳转到搜索标签界面
     *
     * @param activity
     */
    public static void presentSearchTagActivity(Activity activity, int requestCode) {
        if (activity == null) {
            return;
        }

        Intent intent = new Intent(activity, SearchTagActivity.class);
        activity.startActivityForResult(intent, requestCode);
    }

    /**
     * 跳转到用户详情界面
     *
     * @param context
     */
    public static void presentUserActivity(Context context, String userId, String title) {
        if (context == null || UtilString.isBlank(userId)) {
            return;
        }

        Intent intent = new Intent(context, UserActivity.class);
        intent.putExtra(KEY.USER_ID, userId);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }


    /**
     * 跳转到新建收货地址界面
     *
     * @param context
     */
    public static void presentEditAddressActivity(Context context, Address address) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, EditAddressActivity.class);
        intent.putExtra(KEY.ADDRESS , address);
        context.startActivity(intent);
    }

    /**
     * 跳转到地址管理界面
     *
     * @param context
     */
    public static void presentAddressManagerActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, AddressManagerActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到订单界面
     *
     * @param context
     */
    public static void presentOrderActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, OrderActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到订单详情界面
     *
     * @param context
     */
    public static void presentOrderDetailActivity(Context context, String id, String groupBuyId) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, OrderNewDetailActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.GROUPID, groupBuyId);
        context.startActivity(intent);
    }

    /**
     * 跳转到订单详情界面
     *
     * @param context
     */
    public static void presentOrderDetailActivity(Context context, NewOrder order, String groupBuyId) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, OrderNewDetailActivity.class);
        intent.putExtra(KEY.ORDER, order);
        intent.putExtra(KEY.GROUPID, groupBuyId);
        context.startActivity(intent);
    }

    /**
     * 跳转到购物车界面
     *
     * @param context
     */
    public static void presentCartActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, CartNewActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到物流信息界面
     *
     * @param context
     */
    public static void presentExpressActivity(Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ExpressActivity.class);
        intent.putExtra(KEY.ID, id);
        context.startActivity(intent);
    }

    /**
     * 跳转到优惠券界面
     *
     * @param context
     */
    public static void presentCouponActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, CouponActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到拼团界面
     *
     * @param context
     */
    public static void presentGroupActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, GroupActivity.class);
        context.startActivity(intent);
    }


    /**
     * 跳转用户信息修改界面
     *
     * @param context
     */
    public static void presentUserModifyActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, UserModifyActivity.class);
        context.startActivity(intent);
    }


    /**
     * 跳转到晒单详情界面
     *
     * @param context
     */
    public static void presentShareOrderDetailActivity(Context context, Follow follow) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ShareOrderDetailActivity.class);
        intent.putExtra(KEY.FOLLOW, follow);
        context.startActivity(intent);
    }

    /**
     * 跳转到晒单详情界面
     *
     * @param context
     */
    public static void presentShareOrderDetailActivity(Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ShareOrderDetailActivity.class);
        intent.putExtra(KEY.ID, id);
        context.startActivity(intent);
    }

    /**
     * 跳转到品牌详情界面
     *
     * @param context
     */
    public static void presentBrandActivity(Context context, String id, String title) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, BrandActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }

    /**
     * 跳转到话题详情界面
     *
     * @param context
     */
    public static void presentTopicDetailActivity(Context context, String id, String title) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, TopicDetailActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }

    /**
     * 跳转到话题详情界面
     *
     * @param context
     */
    public static void presentWebTopicDetailActivity(Context context, Topic topic) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, WebTopicDetailActivity.class);
        intent.putExtra(KEY.TOPIC, topic);
        context.startActivity(intent);
    }


    /**
     * 跳转到话题详情界面
     *
     * @param context
     */
    public static void presentWebTopicDetailActivity(Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, WebTopicDetailActivity.class);
        intent.putExtra(KEY.ID, id);
        context.startActivity(intent);
    }

    /**
     * 跳转到我的收藏界面
     *
     * @param context
     */
    public static void presentUserCollectionActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, UserCollectionActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到修改密码界面
     *
     * @param context
     */
    public static void presentUserModifyPwdActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, UserModifyPwdActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到确认订单界面
     *
     * @param context
     */
    public static void presentOrderConfirmActivity(Context context, NewOrder result) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, OrderNewConfirmActivity.class);
        intent.putExtra(KEY.ORDER, result);
        context.startActivity(intent);
    }

    /**
     * 跳转到支付结果界面
     *
     * @param context
     */
    public static void presentPayResultActivity(Context context, NewOrder order, String groupBuyId, int status) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, PayResultActivity.class);
        intent.putExtra(KEY.ORDER, order);
        intent.putExtra(KEY.STATUS, status);
        intent.putExtra(KEY.GROUPID, groupBuyId);
        context.startActivity(intent);
    }



    /**
     * 跳转到帖子聚合界面
     *
     * @param context
     */
    public static void presentTagPostsActivity(Context context, String id, String title) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, TagPostsActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }


    /**
     * 跳转到帖子聚合界面
     *
     * @param context
     */
    public static void presentOrderCouponActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, OrderCouponActivity.class);
        context.startActivity(intent);
    }


    /**
     * 跳转到商品列表界面
     *
     * @param context
     */
    public static void presentProductListActivity(Context context, String id, String title) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ProductListActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }

    /**
     * 跳转到商品分仓界面
     *
     * @param context
     */
    public static void presentProductCompartmentActivity(Context context, String id, String title) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ProductCompartmentActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.TITLE, title);
        context.startActivity(intent);
    }

    /**
     * 跳转到热销榜单界面
     *
     * @param context
     */
    public static void presentHotSaleActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, HotSaleActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到视频列表界面
     *
     * @param context
     */
    public static void presentVideoListActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, VideoListActivity.class);
        context.startActivity(intent);
    }


    /**
     * 跳转到商品专题界面
     *
     * @param context
     */
    public static void presentGoodsTopicActivity(Context context, String id, String url) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, GoodsTopicActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.URL, url);
        context.startActivity(intent);
    }

    /**
     * 跳转到视频播放界面
     *
     * @param context
     */
    public static void presentVideoPlayerActivity(Context context, String id, String url) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, VideoPlayerActivity.class);
        intent.putExtra(KEY.ID, id);
        intent.putExtra(KEY.URL, url);
        context.startActivity(intent);
    }


    /**
     * 跳转到图片标签编辑界面
     *
     * @param activity
     */
    public static void presentImageTagEditActivity(Activity activity, String path, int requestCode) {
        if (activity == null || UtilString.isBlank(path)) {
            return;
        }

        Intent intent = new Intent(activity, ImageTagEditActivity.class);
        intent.putExtra(KEY.PATH, path);
        activity.startActivityForResult(intent, requestCode);
    }

    /**
     * 跳转到图片标签搜索界面
     *
     * @param context
     */
    public static void presentImageTagSearchActivity(Context context, int type) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, ImageTagSearchActivity.class);
        intent.putExtra(KEY.TYPE, type);
        context.startActivity(intent);
    }

    /**
     * 跳转到心愿单界面
     *
     * @param context
     */
    public static void presentWishListActivity(Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent(context, WishListActivity.class);
        context.startActivity(intent);
    }

    //==========fragment跳转=================

    /**
     * 扭蛋中心界面
     * @param activity
     */
    public static void presentCenterFragment(NDNiudanActivity activity) {
        if(activity != null) {
            activity.addFragment(NDCenterFragment.class);
        }
    }


    /**
     * 扭蛋列表界面
     * @param activity
     */
    public static void presentOptionsFragment(NDNiudanActivity activity) {
        if(activity != null) {
            activity.addFragment(NDOptionsFragment.class);
        }
    }


    /**
     * 扭券库界面
     * @param activity
     */
    public static void presentCouponFragment(NDNiudanActivity activity) {
        if(activity != null) {
            activity.addFragment(NDCouponFragment.class);
        }
    }



    /**
     * 扭蛋图鉴界面
     * @param activity
     */
    public static void presentImageFragment(NDNiudanActivity activity) {
        if(activity != null) {
            activity.addFragment(NDImageFragment.class);
        }
    }

    /**
     * 扭蛋详情界面
     * @param activity
     * @param niudan
     */
    public static void presentDetailFragment(NDNiudanActivity activity, Niudan niudan) {
        if(activity != null && niudan != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable(CstOuer.KEY.NIUDAN, niudan);
            activity.addFragment(NDDetailFragment.class, bundle);
        }
    }


    /**
     * 扭蛋机动界面
     * @param activity
     * @param niudan
     */
    public static void presentPlayFragment(NDNiudanActivity activity, Niudan niudan) {
        if(activity != null  && niudan != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable(CstOuer.KEY.NIUDAN, niudan);
            activity.addFragment(NDPlayFragment.class, bundle);
        }
    }






    //==========service启动=================
    /**
     * 启动本地服务
     */
    public static void startOuerService(Context context) {
        if(context == null) {
            return;
        }

        Intent serviceIntent = new Intent(context, OuerService.class);
        context.startService(serviceIntent);
    }
	
	//==========broadcast发送=================
	/**
     * 发送用户需要登录广播
     * 
     * @param context
     */
    public static void sendNeedLoginBroadcast(@NonNull Context context) {
    	if(context == null) {
    		return;
    	}
    	
    	Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.NEED_LOGIN_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }
    
    /**
     * 发送用户登录广播
     * 
     * @param context
     */
    public static void sendLoginedBroadcast(@NonNull Context context) {
    	if(context == null) {
    		return;
    	}
    	
    	Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.LOGINED_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }
    
    
    /**
     * 发送用户未登录广播
     * 
     * @param context
     */
    public static void sendUnLoginedBroadcast(@NonNull Context context) {
    	if(context == null) {
    		return;
    	}
    	
    	Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.UNLOGINED_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 发送用户信息修改登录广播
     *
     * @param context
     */
    public static void sendUserModifyBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.USER_MODIFY_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 发送地址信息修改广播
     *
     * @param context
     */
    public static void sendAddressChangeBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ADDRESS_CHANGE_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 订单取消广播
     *
     * @param context
     */
    public static void sendOrderCancelBroadcast(@NonNull Context context, String id) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ORDER_CANCEL_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 确认收货广播
     *
     * @param context
     */
    public static void sendOrderConfirmBroadcast(@NonNull Context context, String id) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ORDER_CONFIRM_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 订单支付成功广播
     *
     * @param context
     */
    public static void sendOrderPayBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ORDER_PAY_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }


    /**
     * 订单提交广播
     *
     * @param context
     */
    public static void sendOrderSubmitBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ORDER_SUBMIT_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 微信支付结果广播
     *
     * @param context
     */
    public static void sendWxPayResultBroadcast(@NonNull Context context, int code) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.WEIXIN_PAY_ACTION);
        intent.putExtra(KEY.CODE, code);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }



    /**
     * 拼团取消广播
     *
     * @param context
     */
    public static void sendGroupCancelBroadcast(@NonNull Context context, String id) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.GROUP_CANCEL_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 拼团完成广播
     *
     * @param context
     */
    public static void sendGroupFinishBroadcast(@NonNull Context context, String id) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.GROUP_FINISH_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 话题关注广播
     *
     * @param context
     */
    public static void sendTopicFollowBroadcast(@NonNull Context context, String id) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.TOPIC_FOLLOW_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }

    /**
     * 寄送扭蛋广播
     *
     * @param context
     */
    public static void sendNiudanSendBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.NIUDAN_SEND_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }


    /**
     * 扭蛋广播
     *
     * @param context
     */
    public static void sendNiudanPlayBroadcast(@NonNull Context context) {
        if(context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.NIUDAN_PLAY_ACTION);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
        manager.sendBroadcast(intent);
    }


    /**
     * 发送忘记密码修改广播
     *
     * @param context
     */
    public static void sendForgetPwdBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.FORGET_PWD_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 发送关注or取消关注广播
     *
     * @param context
     */
    public static void sendFollowBroadcast(@NonNull Context context, String targetId, boolean checked) {
        if (context == null) {
            return;
        }

        FollowReq req = new FollowReq();
        req.setTargetId(targetId);
        req.setChecked(checked);

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.FOLLOW_ACTION);
        intent.putExtra(KEY.FOLLOW, req);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 发送晒单点赞广播
     *
     * @param context
     */
    public static void sendShareOrderLikeBroadcast(@NonNull Context context, ShareOrderLikeReq req) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.SHARE_ORDER_LIKE_ACTION);
        intent.putExtra(KEY.LIKE, req);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发送晒单评论广播
     *
     * @param context
     */
    public static void sendShareOrderCommentBroadcast(@NonNull Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.SHARE_ORDER_COMMENT_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发布晒单广播
     *
     * @param context
     */
    public static void sendShareOrderAddBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.SHARE_ORDER_ADD_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发布接受推送消息广播
     *
     * @param context
     */
    public static void sendMessageBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.MESSAGE_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 发布添加商品到购物车消息广播
     *
     * @param context
     */
    public static void sendAddCartBroadcast(@NonNull Context context, int num) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ADD_CART_ACTION);
        intent.putExtra(KEY.CART_NUM, num);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 删除购物车商品广播
     *
     * @param context
     */
    public static void deleteCartBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.DELETE_CART_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 删除购物车商品广播
     *
     * @param context
     */
    public static void editCartBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.EDIT_CART_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 购物车商品全选广播
     *
     * @param context
     */
    public static void sendCartSelectAllBroadcast(@NonNull Context context, boolean selectAll) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.CART_SELECT_ALL_ACTION);
        intent.putExtra(KEY.SELECTALL, selectAll);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发送主界面tab改变广播
     *
     * @param context
     */
    public static void sendMainTabChangedBroadcast(@NonNull Context context, int index) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.MAINTAB_CHANGED_ACTION);
        intent.putExtra(KEY.INDEX, index);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发布专题喜欢消息广播
     *
     * @param context
     */
    public static void sendTopicFaverBroadcast(@NonNull Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.TOPIC_FAVER_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发布专题添加评论广播
     *
     * @param context
     */
    public static void sendTopicAddCommnetBroadcast(@NonNull Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.TOPIC_ADD_COMMENT_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 发布专题添加评论广播
     *
     * @param context
     */
    public static void sendOrderCouponBroadcast(@NonNull Context context, NewOrder order) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.ORDER_COUPON_PRESUBMIT_ACTION);
        intent.putExtra(KEY.ORDER, order);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 视频收藏广播
     *
     * @param context
     */
    public static void sendVideoFollowBroadcast(@NonNull Context context, String id) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.VIDEO_FOLLOW_ACTION);
        intent.putExtra(KEY.ID, id);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 视频收藏广播
     *
     * @param context
     */
    public static void sendImageTagEditBroadcast(@NonNull Context context, int type, String tag) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.IAMGE_TAG_EDIT_ACTION);
        intent.putExtra(KEY.TYPE, type);
        intent.putExtra(KEY.TAGS, tag);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }


    /**
     * 视频收藏广播
     *
     * @param context
     */
    public static void sendUserSignBroadcast(@NonNull Context context) {
        if (context == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(BROADCAST_ACTION.USER_SIGN_ACTION);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    //==========fragment切换=================
    
	
	//==========message分发=================

    /**
     * 取消消息
     * @param context
     * @param id
     */
    public static void cancelMessage(Context context,int id) {
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(id);
    }


    /**
     * 分发消息
     * @param context
     * @param msg
     */
    public static void notifyMessage(Context context, MiPushMessage msg) {
        Map<String, String> map = msg.getExtra();
        String type = null;
        String value = null;
        try {
            String extra = map == null ? null : map.get(KEY.MAP);
            JSONObject jsonObject = new JSONObject(extra);
            type = jsonObject.getString(KEY.TYPE);
            value = jsonObject.getString(KEY.VALUE);
        } catch (Exception ex) {

        }

        if(!"10".equals(type) || !"11".equals(type) || !"12".equals(type) || !"13".equals(type)) {
            OuerApplication.mPreferences.setMessage(true);
            OuerDispatcher.sendMessageBroadcast(context);
        }

        if (context == null || UtilString.isBlank(msg.getContent())
                || !OuerApplication.mPreferences.getPushEnable()) {
            return;
        }


        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        Intent intent = new Intent();

        if("10".equals(type)) {//专题消息
            intent.setClass(context, WebTopicDetailActivity.class);
            intent.putExtra(KEY.ID, value);
        } else if("11".equals(type)) {//商品消息
            intent.setClass(context, ProductDetailActivity.class);
            intent.putExtra(KEY.ID, value);
        } else if("12".equals(type)) {//帖子消息
            intent.setClass(context, ShareOrderDetailActivity.class);
            intent.putExtra(KEY.ID, value);
        } else if("13".equals(type)) {//活动消息
            intent.setClass(context, WebActivity.class);
            intent.putExtra(KEY.URL, value);
        } else {
            intent.setClass(context, MessageActivity.class);
            intent.putExtra(KEY.INDEX, 0);
        }

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pIntent = PendingIntent.getActivity(context, 100, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pIntent);
        builder.setSmallIcon(R.drawable.common_ic_launcher);
        builder.setDefaults(Notification.DEFAULT_SOUND);
        builder.setWhen(System.currentTimeMillis());
        builder.setContentTitle(context.getString(R.string.app_name));
        builder.setContentText(msg.getContent());
        Notification notification = builder.build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, notification);
    }

    /**
     * 分发消息
     * @param context
     * @param msg
     */
//    public static void notifyMessage(Context context, Message msg) {
//        if (context == null || msg == null
//                || !OuerApplication.mPreferences.getPushEnable()) {
//            return;
//        }
//
//        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
//
//        Intent intent = new Intent();
//        int type = msg.getType();
//        if (type == EMessageType.MESSAGE_FANS) {//进入粉丝
//            intent.setClass(context, MessageActivity.class);
//            intent.putExtra(KEY.INDEX, 3);
//        } else if(type == EMessageType.MESSAGE_LIKE) {//进入新的赞列表
//            intent.setClass(context, MessageActivity.class);
//            intent.putExtra(KEY.INDEX, 1);
//        } else if(type == EMessageType.MESSAGE_COMMENT) {//进入新的评论列表
//            intent.setClass(context, MessageActivity.class);
//            intent.putExtra(KEY.INDEX, 2);
//        } else if(type == EMessageType.MESSAGE_NOTICE) {//进入新的官方通知列表
//            intent.setClass(context, MessageActivity.class);
//            intent.putExtra(KEY.INDEX, 0);
//        }
//
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        PendingIntent pIntent = PendingIntent.getActivity(context, msg.getId().hashCode(), intent,
//                PendingIntent.FLAG_UPDATE_CURRENT);
//        builder.setContentIntent(pIntent);
//        builder.setSmallIcon(R.drawable.common_ic_launcher);
//        builder.setDefaults(Notification.DEFAULT_SOUND);
//        builder.setWhen(msg.getCreateAt());
//
//        String title = msg.getTitle();
//        if (UtilString.isBlank(title)) {
//            title = context.getString(R.string.app_name);
//        }
//        builder.setContentTitle(title);
//        String desc = UtilString.nullToEmpty(msg.getContent());
//        builder.setContentText(desc);
//        Notification notification = builder.build();
//        notification.flags = Notification.FLAG_AUTO_CANCEL;
//
//        NotificationManager manager = (NotificationManager) context
//                .getSystemService(Context.NOTIFICATION_SERVICE);
//        manager.notify(msg.getId().hashCode(), notification);
//    }
	
	//==========H5跳转本地=================
    /**
     * 本地webview跳转到本地界面
     *
     * @param activity
     * @param url
     * @return
     */
    public static boolean localUriLoading(Activity activity, String url) {
        if (activity == null || UtilString.isBlank(url)) {
            return false;
        }

        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();
        String host = uri.getHost();
        String path = uri.getPath();
        try {
            if (CstOuer.SCHEMA.MOEKOU.equals(scheme)
                    && CstOuer.SCHEMA_HOST.MOEKOU_HOST.equals(host)) {
                if (CstOuer.SCHEMA_HOST_PATH.BRAND.equals(path)) {// 品牌详情界面
                    String id = uri.getQueryParameter(KEY.ID);
                    OuerDispatcher.presentBrandActivity(activity, id, null);
                    return true;
                } else if (CstOuer.SCHEMA_HOST_PATH.PRODUCT.equals(path)) {// 商品详情界面
                    String id = uri.getQueryParameter(KEY.ID);
                    OuerDispatcher.presentProductDetailActivity(activity, id);
                    return true;
                }

            }
        } catch (Exception ex) {
            UtilLog.e("error parameter: " + ex.getMessage());
        }

        return false;
    }



}
